package com.abc.server;

import java.util.concurrent.TimeUnit;

import org.apache.http.client.config.RequestConfig;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.apache.solr.client.solrj.impl.HttpSolrClient;

public class SolrServer {
	
	
	private HttpSolrClient server;
	
	
	private SolrServer() {
		
		HttpClientBuilder builder = HttpClientBuilder.create();
		PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager(10, TimeUnit.SECONDS);
		connManager.setMaxTotal(1000);
		RequestConfig config = RequestConfig.custom()
				.setConnectTimeout(5000)//客户端和服务器建立连接的timeout
				.setConnectionRequestTimeout(60000)//从连接池获取连接的timeout
				.setSocketTimeout(5000).build();//客户端从服务器读取数据的timeout
		builder.setDefaultRequestConfig(config);
		builder.setConnectionManager(connManager);
		CloseableHttpClient httpClient = builder.build();

		server = new HttpSolrClient.Builder().withHttpClient(httpClient).build();
		
	}

	
	private static class Holder{
		private static final SolrServer INSTANCE = new SolrServer();
	}
	
	public static HttpSolrClient getServer() {
		return Holder.INSTANCE.server;
	}
}
